package com.example.canvas;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PointF;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;

public class TextCanvasView extends View {
    Paint paint;
    private ArrayList<PointF>graphics = new ArrayList<>();
    PointF point;
    public TextCanvasView(Context context){
        super(context);
        paint = new Paint(); //设置一个笔刷大小是3的黄色的画笔
        paint.setColor(Color.RED);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeWidth(8);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        graphics.add(new PointF(event.getX(),event.getY()));
        Log.d("tangzilin","Points"+event.getX()+":"+event.getY());
        invalidate(); //重新绘制区域
        return true;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//        canvas.drawLine(50,50,50,50,paint);
//        for(PointF point :graphics){  //画点
//            canvas.drawPoint(point.x,point.y,paint);
//        }
        canvas.drawLine(100, 100, 100, 800, paint);
    }
}
